package logic

import (
	"context"
	"fmt"
	"hire/hirerpc/hirerpc"
	"hire/hirerpc/internal/svc"
	"hire/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type PublishAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishAddLogic {
	return &PublishAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PublishAddLogic) PublishAdd(in *hirerpc.PublishAddRequest) (*hirerpc.PublishAddResponse, error) {
	// todo: add your logic here and delete this line
	if in.Name == "" || in.Types == "" || in.Label == "" || in.Money == 0 || in.WordNear == "" || in.Request == "" || in.DescRi == "" {
		return nil, fmt.Errorf("参数不能为空")
	}
	publish := mysql.Publish{
		Name:     in.Name,
		Types:    in.Types,
		Address:  in.Address,
		Label:    in.Label,
		Money:    float64(in.Money),
		WorkNear: in.WordNear,
		Request:  in.Request,
		DescRi:   in.DescRi,
	}
	mysql.DB.Debug().Create(&publish)
	return &hirerpc.PublishAddResponse{
		PublishId: int64(publish.ID),
	}, nil
}
